#include "sdlManager.h"
#include "dv_sdlgrafix.h"
#include "Game.h"


//constructor
sdlManager::sdlManager(void)
{	
	beastRider = NULL;
	dragon = NULL;
	dwarf = NULL;
	elf = NULL;
	flag = NULL;
	knight = NULL;
	mage = NULL;
	scout = NULL;
	slayer2 = NULL;
	yeti = NULL;
	trap = NULL;
	sorcerer = NULL;
	explosion = NULL;
	MoveMarker = NULL;

	settingBoard = true;
	buttonDownL = false;
	buttonDownR = false;
	

}
//destructor
sdlManager::~sdlManager(void)
{
}
void sdlManager::outPutBoard()
{
	for(int y = 0; y < 8; ++y)
		for(int x = 0; x < 10; ++x)
		{
			if(board[y][x].occupied)
			{
				cout << "Type : " << board[y][x].piece << endl;
				cout << "Grid Location : " << x << "," << y << endl;
				cout << "Coordinates : " << board[y][x].location.Xpos << "," << board[y][x].location.Ypos << endl;
				cout << "Number of pieces on board : " << pieces.size() << endl;
				for(int i = 0; i < pieces.size(); ++i)
				{
					cout << "Piece at location " << i << " is " << pieces.at(i).piece << endl;
				}
				cout << endl;
			}
		}
}

void sdlManager::shutdown()
{
	SDL_FreeSurface(background);
	SDL_FreeSurface(World);
	SDL_FreeSurface(Marker);
	SDL_FreeSurface(beastRider);
	SDL_FreeSurface(dragon);
	SDL_FreeSurface(dwarf);
	SDL_FreeSurface(elf);
	SDL_FreeSurface(scout);
	SDL_FreeSurface(mage);
	SDL_FreeSurface(slayer2);
	SDL_FreeSurface(flag);
	SDL_FreeSurface(knight);
	SDL_FreeSurface(yeti);
	SDL_FreeSurface(trap);
	SDL_FreeSurface(sorcerer);
	SDL_FreeSurface(explosion);
	TTF_CloseFont(font);
}

//function to load images
SDL_Surface* sdlManager::load_image( std::string filename ) 
{ //Temporary storage for the image that's loaded
	SDL_Surface* loadedImage = NULL;
	//The optimized image that will be used
	SDL_Surface* optimizedImage = NULL;
	//Load the image
	loadedImage = SDL_LoadBMP( filename.c_str() ); 

	//If nothing went wrong in loading the image
	if( loadedImage != NULL ) 
	{
		//Create an optimized image
		optimizedImage = SDL_DisplayFormat( loadedImage );
		//Free the old image
		SDL_FreeSurface( loadedImage );
	} 
//Return the optimized image
return optimizedImage;
}

void sdlManager::apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination, SDL_Rect* clip = NULL) 
{ //Make a temporary rectangle to hold the offsets
	SDL_Rect offset; 
	//Give the offsets to the rectangle
	offset.x = x;
	offset.y = y; 
	//Blit the surface
	SDL_BlitSurface( source, clip, destination, &offset ); 
}

void sdlManager::draw(SDL_Surface * screen)
{
	BoardGame character;
	
		// clear the screen with black
		SDL_FillRect(screen, 0,0);
		//draw Background
		apply_surface(0,0,background, screen, NULL);
		//draw World
		apply_surface(0,0,World,screen,NULL);
		//for mouse highlighting
		if(mouseInBounds())
			apply_surface(board[mouseXY.Ypos/75][mouseXY.Xpos/70].location.Xpos,board[mouseXY.Ypos/75][mouseXY.Xpos/70].location.Ypos,Marker,screen,NULL);
		//for setting up the pieces on the board
		if(settingBoard)
		{
			piecePlacement(screen);

		}
		if(!settingBoard)
		{
			pieceSelection(screen);
		}
		


		for(int i = 0; i < pieces.size(); i++)
		{	
			if(!pieces.empty())
			{
				switch(pieces.at(i).piece)
				{
				case character.SLAYER:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, slayer2, screen, &frameSL[pieces.at(i).frameCounter]);
					break;
				case character.SCOUT:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, scout, screen, &frameSC[pieces.at(i).frameCounter]);
					break;
				case character.DWARF:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, dwarf, screen, &frameDW[pieces.at(i).frameCounter]);
					break;
				case character.ELF:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, elf, screen, &frameEL[pieces.at(i).frameCounter]);
					break;
				case character.YETI:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, yeti, screen, &frameYE[pieces.at(i).frameCounter]);
					break;
				case character.SORCERER:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, sorcerer, screen, &frameSO[pieces.at(i).frameCounter]);
					break;
				case character.BEASTRIDER:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, beastRider, screen, &frameBR[pieces.at(i).frameCounter]);	
					break;
				case character.KNIGHT:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, knight, screen, &frameKN[pieces.at(i).frameCounter]);
					break;
				case character.MAGE:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, mage, screen, &frameMA[pieces.at(i).frameCounter]);
					break;
				case character.DRAGON:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, dragon, screen, &frameDR[pieces.at(i).frameCounter]);
					break;
				case character.FLAG:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, flag, screen, &frameFL[pieces.at(i).frameCounter]);
					break;
				case character.TRAP:
					apply_surface(pieces.at(i).location.Xpos, pieces.at(i).location.Ypos, trap, screen, NULL);
					break;
				default:
					break;
				}
			}
		}
		
		//messages
		/*SDL_Surface *message;
		message = TTF_RenderText_Solid( font, "Illegal Move", textColor );
		apply_surface( 600, 375, message, screen, NULL );
		SDL_FreeSurface(message);*/
		
		// flip the screen buffer
		SDL_Flip(screen);

		
		
}
void sdlManager::updateFrames()
{
	BoardGame character;

		if(settingBoard)
		{
		frameSL[0].x = 0;
		frameSL[0].y = 0;
		frameSL[0].w = 60;
		frameSL[0].h = 60;

		frameBR[0].x = 0;
		frameBR[0].y = 0;
		frameBR[0].w = 80;
		frameBR[0].h = 70;

		frameDR[0].x = 0;
		frameDR[0].y = 0;
		frameDR[0].w = 100;
		frameDR[0].h = 100;

		frameDW[0].x = 0;
		frameDW[0].y = 0;
		frameDW[0].w = 50;
		frameDW[0].h = 50;

		frameEL[0].x = 0;
		frameEL[0].y = 0;
		frameEL[0].w = 60;
		frameEL[0].h = 60;
		
		frameKN[0].x = 0;
		frameKN[0].y = 0;
		frameKN[0].w = 60;
		frameKN[0].h = 60;

		frameMA[0].x = 0;
		frameMA[0].y = 0;
		frameMA[0].w = 60;
		frameMA[0].h = 60;

		frameSC[0].x = 0;
		frameSC[0].y = 0;
		frameSC[0].w = 60;
		frameSC[0].h = 60;
		
	
		frameFL[0].x = 0;
		frameFL[0].y = 0;
		frameFL[0].w = 80;
		frameFL[0].h = 60;
	
	
		frameYE[0].x = 0;
		frameYE[0].y = 0;
		frameYE[0].w = 60;
		frameYE[0].h = 60;
	
	
		frameSO[0].x = 0;
		frameSO[0].y = 0;
		frameSO[0].w = 60;
		frameSO[0].h = 60;
		}
	
		//this is for animation through time
	static bool restartTime = true;
	static clock_t start = clock();
	float ellapseTime;
	
	if(restartTime)
	{
		start = clock();
		restartTime = false;
			
	}
	ellapseTime = (clock() - start);
	//algo for animations go here (down at if statement)
	if(ellapseTime >= 60)
	{
	

		for(int i = 0; i < pieces.size(); i++)
		{
			//check to see if there is any animation to animate
			if(pieces.at(i).attackLeft || pieces.at(i).attackRight|| pieces.at(i).movingLeft || pieces.at(i).movingRight)
			{
			pieces.at(i).frameCounter += 1;
			}

			// checks to see which pieces to animate
			switch(pieces.at(i).piece)
			{
			case character.SLAYER:
				if(pieces.at(i).movingLeft)
					{
					frameSL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameSL[pieces.at(i).frameCounter].y = 60;
					frameSL[pieces.at(i).frameCounter].w = 60;
					frameSL[pieces.at(i).frameCounter].h = 60;
					if(pieces.at(i).frameCounter >= 14)
						{
							pieces.at(i).frameCounter = 1;
						}
					
					}
				else if (pieces.at(i).movingRight)
				{
					frameSL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameSL[pieces.at(i).frameCounter].y = 0;
					frameSL[pieces.at(i).frameCounter].w = 60;
					frameSL[pieces.at(i).frameCounter].h = 60;
					if(pieces.at(i).frameCounter >= 14)
						{
							pieces.at(i).frameCounter = 1;
						}
				}

				else if(pieces.at(i).attackLeft)
					{
					frameSL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameSL[pieces.at(i).frameCounter].y = 180;
					frameSL[pieces.at(i).frameCounter].w = 60;
					frameSL[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 2)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackRight)
				{
					frameSL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameSL[pieces.at(i).frameCounter].y = 120;
					frameSL[pieces.at(i).frameCounter].w = 60;
					frameSL[pieces.at(i).frameCounter].h = 60;
					if(pieces.at(i).frameCounter == 2)
						{
							pieces.at(i).frameCounter = 0;
						}
				}
				break;
			case character.SCOUT:
				if(pieces.at(i).movingLeft)
					{
					frameSC[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameSC[pieces.at(i).frameCounter].y = 60;
					frameSC[pieces.at(i).frameCounter].w = 60;
					frameSC[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter >= 12)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).movingRight)
					{
					frameSC[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameSC[pieces.at(i).frameCounter].y = 0;
					frameSC[pieces.at(i).frameCounter].w = 60;
					frameSC[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter >= 12)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackLeft)
					{
						frameSC[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameSC[pieces.at(i).frameCounter].y = 180;
						frameSC[pieces.at(i).frameCounter].w = 60;
						frameSC[pieces.at(i).frameCounter].h = 60;

						if(pieces.at(i).frameCounter == 6)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackRight)
					{
						frameSC[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameSC[pieces.at(i).frameCounter].y = 120;
						frameSC[pieces.at(i).frameCounter].w = 60;
						frameSC[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 6)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				break;
			case character.DWARF:
				if(pieces.at(i).movingLeft)
					{
						
					frameDW[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 50;
					frameDW[pieces.at(i).frameCounter].y = 50;
					frameDW[pieces.at(i).frameCounter].w = 50;
					frameDW[pieces.at(i).frameCounter].h = 50;
						if(pieces.at(i).frameCounter == 6)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).movingRight)
					{
					frameDW[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 50;
					frameDW[pieces.at(i).frameCounter].y = 0;
					frameDW[pieces.at(i).frameCounter].w = 50;
					frameDW[pieces.at(i).frameCounter].h = 50;
						if(pieces.at(i).frameCounter == 6)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackLeft)
					{
					frameDW[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 50;
					frameDW[pieces.at(i).frameCounter].y = 150;
					frameDW[pieces.at(i).frameCounter].w = 50;
					frameDW[pieces.at(i).frameCounter].h = 50;
						if(pieces.at(i).frameCounter == 5)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackRight)
					{
					frameDW[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 50;
					frameDW[pieces.at(i).frameCounter].y = 100;
					frameDW[pieces.at(i).frameCounter].w = 50;
					frameDW[pieces.at(i).frameCounter].h = 50;
						if(pieces.at(i).frameCounter == 5)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				break;
			case character.ELF:
				if(pieces.at(i).movingLeft)
					{
					frameEL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameEL[pieces.at(i).frameCounter].y = 60;
					frameEL[pieces.at(i).frameCounter].w = 60;
					frameEL[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 6)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).movingRight)
					{
					frameEL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameEL[pieces.at(i).frameCounter].y = 0;
					frameEL[pieces.at(i).frameCounter].w = 60;
					frameEL[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 6)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackLeft)
					{
					frameEL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameEL[pieces.at(i).frameCounter].y = 180;
					frameEL[pieces.at(i).frameCounter].w = 60;
					frameEL[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 5)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackRight)
					{
					frameEL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameEL[pieces.at(i).frameCounter].y = 180;
					frameEL[pieces.at(i).frameCounter].w = 60;
					frameEL[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 5)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				break;
			case character.YETI:
				if(pieces.at(i).movingLeft)
					{
						frameYE[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameYE[pieces.at(i).frameCounter].y = 60;
						frameYE[pieces.at(i).frameCounter].w = 60;
						frameYE[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 15)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).movingRight)
					{
						frameYE[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameYE[pieces.at(i).frameCounter].y = 0;
						frameYE[pieces.at(i).frameCounter].w = 60;
						frameYE[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 15)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackLeft)
					{
						frameYE[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameYE[pieces.at(i).frameCounter].y = 180;
						frameYE[pieces.at(i).frameCounter].w = 60;
						frameYE[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 1)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackRight)
					{
						frameYE[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameYE[pieces.at(i).frameCounter].y = 120;
						frameYE[pieces.at(i).frameCounter].w = 60;
						frameYE[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 1)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				break;
			case character.SORCERER:
				if(pieces.at(i).movingLeft || pieces.at(i).movingRight || pieces.at(i).attackLeft || pieces.at(i).attackRight)
					{
					frameSO[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
					frameSO[pieces.at(i).frameCounter].y = 0;
					frameSO[pieces.at(i).frameCounter].w = 60;
					frameSO[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 6)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				break;
			case character.BEASTRIDER:
				if(pieces.at(i).movingLeft)
					{
				frameBR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 80;
				frameBR[pieces.at(i).frameCounter].y = 70;
				frameBR[pieces.at(i).frameCounter].w = 80;
				frameBR[pieces.at(i).frameCounter].h = 70;
						if(pieces.at(i).frameCounter == 5)
						{
								pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).movingRight)
				{
				frameBR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 80;
				frameBR[pieces.at(i).frameCounter].y = 0;
				frameBR[pieces.at(i).frameCounter].w = 80;
				frameBR[pieces.at(i).frameCounter].h = 70;
					if(pieces.at(i).frameCounter == 5)
						{
								pieces.at(i).frameCounter = 0;
						}
				}
				else if(pieces.at(i).attackRight)
				{
				frameBR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 80;
				frameBR[pieces.at(i).frameCounter].y = 0;
				frameBR[pieces.at(i).frameCounter].w = 80;
				frameBR[pieces.at(i).frameCounter].h = 70;
					if(pieces.at(i).frameCounter == 5)
						{
								pieces.at(i).frameCounter = 0;
						}
				}
				else if(pieces.at(i).attackLeft)
				{
				frameBR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 80;
				frameBR[pieces.at(i).frameCounter].y = 0;
				frameBR[pieces.at(i).frameCounter].w = 80;
				frameBR[pieces.at(i).frameCounter].h = 70;
					if(pieces.at(i).frameCounter == 5)
						{
								pieces.at(i).frameCounter = 0;
						}
				}
				break;
			case character.KNIGHT:
				if(pieces.at(i).movingLeft)
					{	
				frameKN[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
				frameKN[pieces.at(i).frameCounter].y = 60;
				frameKN[pieces.at(i).frameCounter].w = 60;
				frameKN[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 15)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).movingRight)
					{
				frameKN[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
				frameKN[pieces.at(i).frameCounter].y = 0;
				frameKN[pieces.at(i).frameCounter].w = 60;
				frameKN[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 15)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackLeft)
					{
				frameKN[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
				frameKN[pieces.at(i).frameCounter].y = 180;
				frameKN[pieces.at(i).frameCounter].w = 60;
				frameKN[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 4)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackRight)
					{
				frameKN[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
				frameKN[pieces.at(i).frameCounter].y = 120;
				frameKN[pieces.at(i).frameCounter].w = 60;
				frameKN[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 4)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				break;
			case character.MAGE:
				if(pieces.at(i).movingLeft)
					{
						frameMA[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameMA[pieces.at(i).frameCounter].y = 60;
						frameMA[pieces.at(i).frameCounter].w = 60;
						frameMA[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 16)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).movingRight)
					{
						frameMA[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameMA[pieces.at(i).frameCounter].y = 0;
						frameMA[pieces.at(i).frameCounter].w = 60;
						frameMA[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 16)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackLeft)
					{
						frameMA[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameMA[pieces.at(i).frameCounter].y = 180;
						frameMA[pieces.at(i).frameCounter].w = 60;
						frameMA[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 2)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				else if(pieces.at(i).attackRight)
					{
						frameMA[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 60;
						frameMA[pieces.at(i).frameCounter].y = 120;
						frameMA[pieces.at(i).frameCounter].w = 60;
						frameMA[pieces.at(i).frameCounter].h = 60;
						if(pieces.at(i).frameCounter == 2)
						{
							pieces.at(i).frameCounter = 0;
						}
					}
				break;
			case character.DRAGON:
				if(pieces.at(i).movingLeft)
				{
					frameDR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 100;
					frameDR[pieces.at(i).frameCounter].y = 100;
					frameDR[pieces.at(i).frameCounter].w = 100;
					frameDR[pieces.at(i).frameCounter].h = 100;
					if(pieces.at(i).frameCounter == 5)
					{
						pieces.at(i).frameCounter = 0;
					}
				}
				else if(pieces.at(i).movingRight)
				{
					frameDR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 100;
					frameDR[pieces.at(i).frameCounter].y = 0;
					frameDR[pieces.at(i).frameCounter].w = 100;
					frameDR[pieces.at(i).frameCounter].h = 100;
					if(pieces.at(i).frameCounter == 5)
					{
						pieces.at(i).frameCounter = 0;
					}
				}
				else if(pieces.at(i).attackLeft)
				{
					frameDR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 100;
					frameDR[pieces.at(i).frameCounter].y = 100;
					frameDR[pieces.at(i).frameCounter].w = 100;
					frameDR[pieces.at(i).frameCounter].h = 100;
					if(pieces.at(i).frameCounter == 5)
					{
						pieces.at(i).frameCounter = 0;
					}
				}
				else if(pieces.at(i).attackRight)
				{
					frameDR[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 100;
					frameDR[pieces.at(i).frameCounter].y = 0;
					frameDR[pieces.at(i).frameCounter].w = 100;
					frameDR[pieces.at(i).frameCounter].h = 100;
					if(pieces.at(i).frameCounter == 5)
					{
						pieces.at(i).frameCounter = 0;
					}
				}
				break;
			case character.FLAG:
				if(pieces.at(i).movingLeft || pieces.at(i).movingRight || pieces.at(i).attackLeft || pieces.at(i).attackRight)
				{
					frameFL[pieces.at(i).frameCounter].x = pieces.at(i).frameCounter * 80;
					frameFL[pieces.at(i).frameCounter].y = 0;
					frameFL[pieces.at(i).frameCounter].w = 80;
					frameFL[pieces.at(i).frameCounter].h = 60;
					if(pieces.at(i).frameCounter >= 9)
					{
						pieces.at(i).frameCounter = 0;
					}
				}
				break;
			default:
				break;
			}					
	}
	restartTime = true;
	}
}
void sdlManager::loadImages()
{
	background = load_image("Background.bmp");
	World = load_image("Board.bmp");
	MoveMarker = load_image("MoveMarker.bmp");
	Marker = load_image("Marker.bmp");
	beastRider = load_image("Beast Rider Sprite Sheet.bmp");
	dragon = load_image("Dragon Sprite Sheet.bmp");
	dwarf = load_image("Dwarf Sprite Sheet.bmp");
	elf = load_image("Elf Sprite Sheet.bmp");
	flag = load_image("Flag Sprite Sheet.bmp");
	knight = load_image("Knight Sprite Sheet.bmp");
	mage = load_image("Mage Sprite Sheet.bmp");
	scout = load_image("Scout Sprite Sheet.bmp");
	slayer2 = load_image("Fiolina Sprite Sheet.bmp");
	yeti = load_image("Yeti Sprite Sheet.bmp");
	trap = load_image("Trap.bmp");
	sorcerer = load_image("Sorcerer Sprite Sheet.bmp");
	explosion = load_image("Explosion Sprite Sheet.bmp");

	//set tranparency for background
	setTransparentColor(sorcerer, 0x00F2FF);
	setTransparentColor(Marker,0x000000);
	setTransparentColor(dragon,0x00F2FF);
	setTransparentColor(beastRider,0x00F2FF);
	setTransparentColor(dwarf,0x00F2FF);
	setTransparentColor(elf,0x00F2FF);
	setTransparentColor(flag,0x00F2FF);
	setTransparentColor(knight,0x00F2FF);
	setTransparentColor(mage,0x00F2FF);
	setTransparentColor(scout,0x00F2FF);
	setTransparentColor(slayer2,0x00F2FF);
	setTransparentColor(yeti,0x00F2FF);
	setTransparentColor(trap,0x00F2FF);
	setTransparentColor(explosion,0xFF0000);		

}

void sdlManager::getMousePosition(int x, int y)
{
	mouseXY.Xpos = x;
	mouseXY.Ypos = y;
}
bool sdlManager::mouseInBounds()
{
	if(mouseXY.Xpos < 0 || mouseXY.Xpos > 700 || mouseXY.Ypos < 0 || mouseXY.Ypos > 600)
		return false;
	return true;
}

void sdlManager::getMouseClick(int xc, int yc)
{
	mouseXYClick.Xpos = xc;
	mouseXYClick.Ypos = yc;
}




